<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="user-form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list">
                    <ul>
                        <li>
                            手机号码：<input type="text" name="phone"/>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">

            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="module:user:add">
                <i class="fa fa-plus"></i> 新增机器人
            </a>

            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="module:user:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>


<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:user:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:user:remove')}]];
    var prefix = ctx + "module/roomUser";
    var userType = [[${@dict.getType('user_type')}]];
    var delFlag = [[${@dict.getType('del_flag')}]];
    var robotType = [[${@dict.getType('robot_type')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "房间用户关联",
            columns: [{
                checkbox: true
            },
                {
                    field: 'uId',
                    title: 'id'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'userType',
                    title: '用户类型 ',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(userType, value);
                    }
                },
                {
                    field: 'userDelFlag',
                    title: '状态 ',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(delFlag, value);
                    }
                },
                {
                    field: 'nickName',
                    title: '昵称 '
                },
                {
                    field: 'money',
                    title: '余额 '
                },
                {
                    field: 'freezeMoney',
                    title: '冻结金额 '
                },
                {
                    field: 'name',
                    title: '所属房间 '
                },
                {
                    field: 'robotType',
                    title: '机器人类型 ',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(robotType, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable:true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.uId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.uId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //
    function checkOrder(id) {
        var url = prefix + '/check';
        var data = {};
        data.id = id;

        var flag = false;

        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            async: false,
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    flag = true;
                } else {
                    $.modal.alertError(result.msg);
                    flag = false;
                }
            }
        };
        $.ajax(config);
        return flag;
    }


    /*借款审核*/
    function addRobot() {
        var id = "";
        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }
        //校验订单
        var flag = checkOrder(id[0], 1);

        if (!flag) {
            return;
        }

        var url = prefix + '/toEdit?id=' + id ;
        $.modal.open("借款审核", url);
    }

</script>
</body>
</html>